# -*-coding:utf-8-*-
import json
import pandas as pd
import numpy as np
import redis
import sys
import time
from datetime import datetime


pool = redis.ConnectionPool(host='localhost',
                            port=6379,
                            decode_responses=True,
                            db=0)
r = redis.Redis(connection_pool=pool)

symbol = sys.argv[1]
symbol = symbol.upper()

last_data = 'xxx'
while True:
    time.sleep(0.8)
    data = r.get(f'{symbol}_depth')
    if data != last_data:
        hour = json.loads(data)['t'][:13]
        open(f'../depth_data/{symbol}_{hour}_depth.txt', 'a').write(f'{data}\n')
        last_data = data